﻿#include "ReleaseNotes.h"
#include "ReleaseNotesModelParser.h"
#include "../StoreFilePath.h"

ReleaseNotes::ReleaseNotes(QObject *parent)
    : IStore<ReleaseNotesModel>{parent}
{
    model().setModelParser(new ReleaseNotesModelParser());
}

bool ReleaseNotes::save()
{
    QFile f(StoreFilePath::releaseNotes());
    if (!f.open(QIODevice::WriteOnly)) {
        return false;
    }
    f.write(model().toString().toUtf8());
    f.close();
    return true;
}

void ReleaseNotes::loadNotes()
{
    QFile f(StoreFilePath::releaseNotes());
    if (!f.open(QIODevice::ReadOnly)) {
        model().setModelData(model().emptyModelData());
        return;
    }
    QByteArray src = f.readAll();
    f.close();
    model().loadFromStr(src);
    if (model().isValid()) {

    } else {
        model().setModelData(model().emptyModelData());
    }
}
